package com.wl156.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.wl156.R;
import com.wl156.activities.find.CarMessageInfo;
import com.wl156.activities.find.GoodInfo;
import com.wl156.model.Wl156DB;

public class OneMessage extends Activity {

	WebView mWebView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act_one_message);

		try {
			Bundle extras = getIntent().getExtras();
			String msg = extras.getString("msg");
			Log.d("MessageCenter", msg);

			String[] line = msg.split("##");

			Wl156DB.markMessageRead(this, line[0]);

			mWebView = (WebView) findViewById(R.id.webview);
			// mWebView.setWebChromeClient(new WebChromeClient());
			mWebView.setWebViewClient(new MyWebViewClient());
			mWebView.loadDataWithBaseURL(null, line[4] == null ? "" : line[4],
					"text/html", "utf-8", null);
		} catch (Exception e) {
		}
	}

	class MyWebViewClient extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			try {
				if (url.startsWith("wl156")) {
					Class target = null;
					long id = Long
							.parseLong(url.substring(url.lastIndexOf("/") + 1));
					if (url.contains("good_message")) {
						target = GoodInfo.class;
					} else if (url.contains("truck_message")) {
						target = CarMessageInfo.class;
					} else if (url.contains("order_message")) {
						// target =
					} else if (url.contains("daijieshou")) {

					} else if (url.contains("bujieshou")) {

					}
					try {
						Intent i = new Intent(OneMessage.this, target);
						i.putExtra("id", id);
						startActivity(i);
					} catch (Exception e) {
					}
					return true;
				} else {
					return super.shouldOverrideUrlLoading(view, url);
				}
			} catch (Exception e) {
				return true;
			}
		}
	}
}
